package com.tgjorgoski.sidekicknotes.htmlview;

import java.awt.Event;
import java.awt.event.KeyEvent;

import javax.swing.InputMap;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;

import com.tgjorgoski.sidekicknotes.rtfview.support.*;

public class KeyBindings {
	public static void setKeyBindings(HTMLEditor comp) {
        InputMap inputMap = comp.getInputMap();//(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        
        //Bold, Italic and Underline are in the actionmap courtesy of StyledEditorKit
        KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK);
        inputMap.put(key, "font-bold");

        key = KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK);
        inputMap.put(key, "font-italic");

        key = KeyStroke.getKeyStroke(KeyEvent.VK_U, Event.CTRL_MASK);
        inputMap.put(key, "font-underline");

        //Superscript, subscript and strikethrough are in the actionmap courtesy of SubSuperStrikeSupport
        key = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, Event.CTRL_MASK);
        inputMap.put(key, SubSuperStrikeSupport.SUPERSCRIPT_KEY);

        key = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, Event.CTRL_MASK + Event.SHIFT_MASK);
        inputMap.put(key, SubSuperStrikeSupport.SUBSCRIPT_KEY);

        key = KeyStroke.getKeyStroke(KeyEvent.VK_U, Event.CTRL_MASK + Event.SHIFT_MASK);
        inputMap.put(key, SubSuperStrikeSupport.STRIKETHROUGH_KEY);

        //Cut, Copy and Paste are in the actionmap, courtesy of DefaultEditorKit
        key = KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK);
        inputMap.put(key, DefaultEditorKit.copyAction);

        key = KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK);
        inputMap.put(key, DefaultEditorKit.cutAction);
        
        key = KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK);
        inputMap.put(key, DefaultEditorKit.pasteAction);

        //Undo and Redo actions are added by the UndoRedoSupport to the actionmap
        key = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK);
        inputMap.put(key, UndoRedoSupport.UNDO_ACTION);
        
        key = KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK);
        inputMap.put(key, UndoRedoSupport.REDO_ACTION);
        
        //Evaluate action is added by the EvaluateSupport
        key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK);
        inputMap.put(key, EvaluateSupport.ACTION_KEY);
        
        //Indent and Unindent actions are added by the IndentSupport
        key = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
        inputMap.put(key, IndentSupport.INDENT_KEY);
        
        key = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Event.SHIFT_MASK);
        inputMap.put(key, IndentSupport.UNINDENT_KEY);

	}
}
